
Volvo.CareTrack.DataloaderClass = function() {
	//
};

proto = Volvo.CareTrack.DataloaderClass.prototype;

proto.searchMachineByDealerID = function(params) {
	
	Volvo.CareTrack.NetworkOperation.request({
		urlPath: '/searchMachine', 
		data: {
			dealerID: params.dealerID
		},
		error: params.error,
		success: function(data) {
			var machineList = [];
			$.each(data, function() {
				var machine = new Volvo.CareTrack.DataModel.Machine();
				machine.chassisNo = this.chassisNo;
				machine.name = this.name;
				machine.model = this.model;
				machine.brand = this.brand;
				machine.type.name = this.type.name;
				machine.type.generation = this.type.generation;
				machine.type.description = this.type.description;
				machineList.push(machine);
			});
			params.success(machineList);
		}
	});
};

proto.getMachinePosition = function(params) {
	
	Volvo.CareTrack.NetworkOperation.request({
		urlPath: '/getMachinePosition', 
		data: {
			chassisNo: params.chassisNo
		},
		error: params.error,
		success: function(data) {
			var machinePosition = new Volvo.CareTrack.DataModel.MachinePosition();
			machinePosition.chassisNo = data.chassisNo;
			machinePosition.longitude = data.longitude;
			machinePosition.latitude = data.latitude;
			machinePosition.altitude = data.altitude;
			machinePosition.reverseGeocoding = data.reverseGeocoding;
			machinePosition.timestamp = data.timestamp;
			machinePosition.fuelLevel = data.fuelLevel;
			machinePosition.state = data.state;
			params.success(machinePosition);
		}
	});
};

proto.login = function(params) {
	
	Volvo.CareTrack.NetworkOperation.request({
		urlPath: '/login', 
		data: {
			username: params.username,
			password: params.password
		},
		error: params.error,
		success: function(data) {
			var sessionID = data.sessionID;
			params.success(sessionID);
		}
	});
};

proto.checkBackend = function(params) {
	
	Volvo.CareTrack.NetworkOperation.request({
		urlPath: '/start', 
		data: {},
		error: params.error,
		success: function(data) {
			params.success(data.isAlive);
		}
	});
};

Volvo.CareTrack.Dataloader = new Volvo.CareTrack.DataloaderClass();